var express = require("express");
const Result = require("../../utils/result");
const { asyncFun } = require("../../middleware/async");
var router = express.Router();

const EduService = require("./admin.service");

// 新增
router.post(
  "/admin/blog/type",
  asyncFun(async function (req, res, next) {
    await EduService.addType(req.body);
    new Result({}, "成功").success(res);
  })
);

// 修改
router.put(
  "/admin/blog/type",
  asyncFun(async function (req, res, next) {
    await EduService.modType(req.body);
    new Result({}, "成功").success(res);
  })
);

// 删除
router.delete(
  "/admin/blog/type/:id",
  asyncFun(async function (req, res, next) {
    await EduService.delType(req.params);
    new Result({}, "成功").success(res);
  })
);

// 查询
router.get(
  "/admin/blog/types",
  asyncFun(async function (req, res, next) {
    const data = await EduService.getTypes(req.query);
    new Result(data, "成功").success(res);
  })
);

// 新增
router.post(
  "/admin/blog/md",
  asyncFun(async function (req, res, next) {
    await EduService.addMd(req.body, req.auth);
    new Result({}, "成功").success(res);
  })
);

// 修改
router.put(
  "/admin/blog/md",
  asyncFun(async function (req, res, next) {
    await EduService.modMd(req.body);
    new Result({}, "成功").success(res);
  })
);

// 删除
router.delete(
  "/admin/blog/md/:id",
  asyncFun(async function (req, res, next) {
    await EduService.delMd(req.params);
    new Result({}, "成功").success(res);
  })
);

// 删除
router.get(
  "/admin/blog/md/:id",
  asyncFun(async function (req, res, next) {
    const data = await EduService.getMd(req.params);
    new Result(data, "成功").success(res);
  })
);

// 查询
router.get(
  "/admin/blog/mds",
  asyncFun(async function (req, res, next) {
    const data = await EduService.getMds(req.query);
    new Result(data, "成功").success(res);
  })
);

// 新增
router.post(
  "/admin/blog/comment",
  asyncFun(async function (req, res, next) {
    await EduService.addComment(req.body);
    new Result({}, "成功").success(res);
  })
);

// 修改
router.put(
  "/admin/blog/comment",
  asyncFun(async function (req, res, next) {
    await EduService.modComment(req.body);
    new Result({}, "成功").success(res);
  })
);

// 删除
router.delete(
  "/admin/blog/comment/:id",
  asyncFun(async function (req, res, next) {
    await EduService.delComment(req.params);
    new Result({}, "成功").success(res);
  })
);

// 查询
router.get(
  "/admin/blog/comments",
  asyncFun(async function (req, res, next) {
    const data = await EduService.getComments(req.query);
    new Result(data, "成功").success(res);
  })
);

module.exports = router;
